/*
 * JniHFileStart.java  0.4.0 / Nov 6, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.tools.ng.jni;

import java.io.IOException;
import java.io.PrintWriter;

import com.thoughtworks.qdox.model.JavaClass;

import com.cute4j.tools.ng.AbstractNativeFile;
import com.cute4j.tools.ng.NativeFileText;
import com.cute4j.tools.ng.Utils;

/**
 * JNI Header File Start.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class JniHFileStart extends NativeFileText {

// Private Fields. -------------------------------------------------------------

  private final JavaClass javaClass;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new JniHFileStart object.
   *
   * @param nativeFile the native file
   * @param javaClass the qdox java class
   */
  public JniHFileStart(AbstractNativeFile nativeFile, JavaClass javaClass) {
    super(nativeFile);
    this.javaClass = javaClass;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  protected void storeContent(PrintWriter pw) throws IOException {
    pw.print("#ifndef ");
    String guard = Utils.getMangledClassName(javaClass).toUpperCase(); //NOFB
    guard = guard + "_H";
    pw.println(guard);
    pw.print("#define ");
    pw.println(guard);
    pw.println();
    pw.println("#include <jni.h>");
    pw.println();
    pw.println("#ifdef __cplusplus");
    pw.println("extern \"C\" {");
    pw.println("#endif // __cplusplus");
    pw.println();
    pw.println("/*");
    pw.print(" * Header file for: ");
    pw.println(Utils.getMangledClassName(javaClass));
    pw.println(" * ");
    pw.println(" * WARNING: DO NOT EDIT THIS FILE - it is machine generated");
    pw.println(" */");
    pw.println();
  }

}
